﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESB.BAM.DAL;

namespace ESB.BAM.BLogic
{
    /// <summary>
    /// This is a class to wrap the row of mapping data.
    /// </summary>
    public class EsbTrackingProfileStep
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EsbTrackingProfileStep"/> class.
        /// </summary>
        /// <param name="DALProfile">The DAL profile.</param>
        public EsbTrackingProfileStep(EsbTrackingProfile DALProfile)
        {
            Id = DALProfile.ID;
            ItineraryName = DALProfile.ItineraryName;
            ServiceName = DALProfile.ServiceName;
            ActivityName = DALProfile.ActivityName;
            MilestoneName = DALProfile.MilestoneName;
            Action = (ItineraryServiceActionEnum)DALProfile.Action;
            MsgIdXPath = DALProfile.MsgIdXPath;
        }
        public long Id { get; set; }
        public string ItineraryName { get; set; }
        public string ServiceName { get; set; }
        public string ActivityName { get; set; }
        public string MilestoneName { get; set; }
        public ItineraryServiceActionEnum Action { get; set; }
        public string MsgIdXPath { get; set; }

        /// <summary>
        /// Gets the profile step.
        /// </summary>
        /// <param name="ItineraryName">Name of the itinerary or orchestration.</param>
        /// <param name="ServiceName">Name of the itinerary service or orchestration shape.</param>
        /// <returns></returns>
        public static EsbTrackingProfileStep GetProfileStep(string ItineraryName, string ServiceName)
        {
            var callToken = Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceIn();
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceInfo("Getting the tracking profile for " + ItineraryName + " ," + ServiceName);
            EsbTrackingProfilesDbCache cache = EsbTrackingProfilesDbCache.GetCache();
            EsbTrackingProfile DALProfile = cache.GetProfileStep(ItineraryName, ServiceName);
            EsbTrackingProfileStep pStep = null;
            if (DALProfile != null)
            {
                pStep = new EsbTrackingProfileStep(DALProfile);
            }
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceOut(callToken);
            return pStep;
        }
    }
}
